package org.grayrabbit.cms.publish.generate;

import java.util.List;

import org.grayrabbit.cms.entity.Admin;
import org.grayrabbit.cms.entity.Category;
import org.grayrabbit.cms.entity.PublishTask;
import org.grayrabbit.cms.entity.Site;
import org.grayrabbit.cms.publish.api.Generatable;
import org.grayrabbit.cms.publish.generate.factory.AbstractFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GenTask implements Runnable {

	private static Logger log = LoggerFactory.getLogger(GenTask.class);

	private List<String> list;
	private String type;
	private Site site;
	private Mission mission;
	private Admin admin;
	private List<Category> taxPath;
	private String ip;
	private int pageSize;
	private int pageNum;
	private String percentKey;

	public String getPercentKey() {
		return percentKey;
	}

	public void setPercentKey(String percentKey) {
		this.percentKey = percentKey;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	private PublishTask publishTask;

	public void setPublishTask(PublishTask publishTask) {
		this.publishTask = publishTask;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public Mission getMission() {
		return mission;
	}

	public void setMission(Mission mission) {
		this.mission = mission;
	}

	public Site getSite() {
		return site;
	}

	public void setSite(Site site) {
		this.site = site;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setList(List<String> list) {
		this.list = list;
	}

	private Generatable generatable;

	public void run() {
		try {
			generatable.genreate(admin,site, type, list, pageSize, pageNum,publishTask);
			// 更新发布状态
		} catch (Exception e) {
			log.error("生成html异常:", e);
		}finally{
			synchronized (AbstractFactory.LOCK) {
				AbstractFactory.taskNum --;
				log.debug("after -- ,current Task num is {}.",AbstractFactory.taskNum);
			}
		}
	}

	public String getType() {
		return type;
	}

	public void setGeneratable(Generatable generatable) {
		this.generatable = generatable;
	}
}
